package com.pac.hospital.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.common.tools.StringTools;
import com.common.util.ErrorNumber;
import com.common.util.LogicException;
import com.pac.hospital.bean.HospitalManagerBean;
import com.pac.hospital.dao.HospitalManagerDao;
import com.pac.hospital.service.HospitalManagerService;

/**
 * 医院管理员Service实现
 * 
 * @author lujun.chen
 * @version [版本号, 2015年3月29日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Service(value = "hospitalManagerService")
public class HospitalManagerServiceImpl implements HospitalManagerService {

	private static Logger logger = Logger
			.getLogger(HospitalManagerServiceImpl.class);

	@Autowired
	private HospitalManagerDao hospitalManagerDao;
	
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean addHospitalManager(HospitalManagerBean hospitalManagerBean) {

		if (null == hospitalManagerBean) {
			logger.error("添加医院管理员出错，参数为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "参数为空");
		}

		if (StringTools.isNull(hospitalManagerBean.getHospitalId())) {
			logger.error("添加医院管理员出错，医院ID为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "医院ID为空");
		}

		if (StringTools.isNull(hospitalManagerBean.getUserId())) {
			logger.error("添加医院管理员出错，用户ID为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "用户ID为空");
		}

		return hospitalManagerDao.addHospitalManager(hospitalManagerBean);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean delHospitalManager(HospitalManagerBean hospitalManagerBean) {

		if (null == hospitalManagerBean) {
			logger.error("删除医院管理员出错，参数为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL, "参数为空");
		}

		if (StringTools.isNull(hospitalManagerBean.getHospitalId())
				&& StringTools.isNull(hospitalManagerBean.getUserId())) {
			logger.error("删除医院管理员出错，医院ID和用户ID不能都为空");
			throw new LogicException(ErrorNumber.PARAM_IS_NULL,
					"医院ID和用户ID不能都为空");
		}
		return hospitalManagerDao.delHospitalManager(hospitalManagerBean);
	}

	@Override
	public List<HospitalManagerBean> queryHospitalManager(
			HospitalManagerBean hospitalManagerBean) {

		return hospitalManagerDao.queryHospitalManager(hospitalManagerBean);

	}

}
